package com.xc.file.web.rest;

import com.xc.core.annotation.Authority;
import com.xc.core.bean.PagingBean;
import com.xc.core.dto.PagingDto;
import com.xc.core.model.TokenModel;
import com.xc.file.bean.SafetyChainBean;
import com.xc.file.dto.SafetyChainDto;
import com.xc.file.service.SafetyChainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>安全链接rest接口</p>
 *
 * @author xc
 * @version v1.0
 */
@Api(tags = "安全链接rest接口")
@RestController
public class SafetyChainRest {

    @Autowired
    private SafetyChainService safetyChainService;

    @ApiOperation(value = "安全链接分页", notes = "获取当前用户的安全链接页")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前页", name = "current", paramType = "path", required = true),
            @ApiImplicitParam(value = "用户token", name = "token", paramType = "header", required = true),
    })
    @GetMapping("/current_user/safety_chain_pages/{current}")
    @Authority
    public PagingDto<SafetyChainDto> getCurrentUserSafetyChainPage(TokenModel tokenModel, @PathVariable Integer current,
                                                                   @ModelAttribute PagingBean pagingBean, @ModelAttribute SafetyChainBean safetyChainBean) {
        return safetyChainService.getUserSafetyChainPage(tokenModel.getUserId(), current, pagingBean, safetyChainBean);
    }

    @ApiOperation(value = "创建安全链接", notes = "创建当前用户的安全链接")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户token", name = "token", paramType = "header", required = true),
    })
    @PostMapping("/current_user/safety_chain")
    @Authority
    public SafetyChainDto createCurrentUserSafetyChain(TokenModel tokenModel, @RequestBody SafetyChainBean safetyChainBean) {
        return safetyChainService.createSafetyChain(tokenModel.getUserId(), safetyChainBean);
    }

    @ApiOperation(value = "修改安全链接", notes = "修改当前用户的安全链接")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "安全链接id", name = "safetyChainId", paramType = "path", required = true),
            @ApiImplicitParam(value = "用户token", name = "token", paramType = "header", required = true),
    })
    @PutMapping("/current_user/safety_chain/{safetyChainId}")
    @Authority
    public SafetyChainDto updateCurrentUserSafetyChain(TokenModel tokenModel, @PathVariable String safetyChainId,
                                                       @RequestBody SafetyChainBean safetyChainBean) {
        return safetyChainService.updateSafetyChain(tokenModel.getUserId(), safetyChainId, safetyChainBean);
    }

    @ApiOperation(value = "删除安全链接", notes = "删除当前用户的安全链接")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "安全链接id", name = "safetyChainId", paramType = "path", required = true),
            @ApiImplicitParam(value = "用户token", name = "token", paramType = "header", required = true),
    })
    @DeleteMapping("/current_user/safety_chain/{safetyChainId}")
    @Authority
    public void deleteCurrentUserSafetyChain(TokenModel tokenModel, @PathVariable String safetyChainId) {
        safetyChainService.deleteUserSafetyChain(tokenModel.getUserId(), safetyChainId);
    }
}
